<?php

namespace App\Http\Requests\Admin;

use App\Http\Requests\ApiRequest;
use Illuminate\Http\UploadedFile;

/**
 * @property string|UploadedFile logo
 */
class PartnerUpdateRequest extends ApiRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {

        if (is_file($this->logo)) {
            return [
                'name'     => 'required|string',
                /** 这个参数禁止给与原bos key相同的网址过来，否则原bos key会被删除，网址无法正常显示，要么就给null回来 */
                'logo'     => 'sometimes|file',
                'url'      => 'sometimes|url',
                'remark'   => 'sometimes|string',
                'priority' => 'sometimes|numeric|min:0'
            ];
        } else {
            return [
                'name'     => 'required|string',
                'logo'     => 'sometimes',
                'url'      => 'sometimes|url',
                'remark'   => 'sometimes|string',
                'priority' => 'sometimes|numeric|min:0'
            ];
        }

    }

    /**
     * @return array
     */
    public function messages()
    {
        return [
            'name.*'     => ':attribute必须是字符串',
            'logo.*'     => ':attribute必须是320 x 134 的png图片',
            'url.*'      => ':attribute必须是合法的url',
            'remark.*'   => ':attribute必须是字符串',
            'priority.*' => ':attribute必须是数值'
        ];
    }

    /**
     * @return array
     */
//    public function attributes()
//    {
//        return [
//            'name'   => '合作伙伴名称',
//            'logo'   => '上传的图片',
//            'url'    => '跳转链接',
//            'remark' => '备注'
//            'priority' => '排序的优先级'
//        ];
//    }
}
